package com.ykg.controller;

import com.ykg.annotation.PassToken;
import com.ykg.dto.ListDTO;
import com.ykg.enums.ResultEnum;
import com.ykg.interceptor.ScopeLevel;
import com.ykg.pojo.ListCharge;
import com.ykg.service.IAgentService;
import com.ykg.service.IListService;
import com.ykg.util.ResultResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Objects;

/**
 *
 * 类(接口)：
 * Created on 8:03 2021/6/24.
 *
 * @Author: laobian
 * @Description:
 */
@Api(tags = "船货代Api")
@RestController
@RequestMapping("/api/agent")
public class AgentController {
    @Autowired
    private IAgentService agentService;

    @Autowired
    private IListService listService;

    //@PassToken
    @PostMapping(value = "/checkin",produces = "application/json")
    @ApiOperation("审核卸货清单")
    @ScopeLevel(value = 10)
    public ResultResponse checkinList(@RequestParam String listId){
        if(Objects.isNull(listId)){
            return new ResultResponse(ResultEnum.PARAM_ERROR);
        }
        int status = agentService.checkListCharge(listId);
        if(status==0){
            return new ResultResponse(ResultEnum.FAILURE);
        }
        return new ResultResponse(ResultEnum.SUCCESS);
    }

    //@PassToken
    @GetMapping(value = "/all",produces = "application/json")
    @ApiOperation("获取全部的卸货清单")
    @ScopeLevel(value = 10)
    public ResultResponse findAll(HttpServletRequest request){
        List<ListCharge> listCharges = listService.findAllList();
        System.out.println(request.getServletPath());
        return new ResultResponse(listCharges);
    }


    //@PassToken
    @GetMapping(value = "/{listId}",produces = "application/json")
    @ApiOperation("获取某个清单的详情")
    @ScopeLevel(value = 10)
    public ResultResponse findListById(@PathVariable(value = "listId") String listId){
        ListDTO listDTO  = listService.findListByListId(listId);
        return  new ResultResponse(listDTO);
    }



}
